﻿namespace CheckIn.AdminServer.Controllers.ActivitySrc
{
    using CheckIn.AdminServer.PlanDBModels;
    using DawnAdminServer.Attributes;
    using DawnAdminServer.Controllers;
    using DawnAdminServer.Dtos;
    using Microsoft.AspNetCore.Authorization;
    using Microsoft.AspNetCore.Mvc;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    [MatchPath("activity/ActivityView")]
    public class ActivityActivityJoinController : EfReadonlyControllerBase<PlanDBContext, ActivityJoin, ActivityJoinSearchModel>
    {
        public override Task<PageData<object>> List([FromBody] ActivityJoinSearchModel model)
        {
            return base.List(model);
        }

        [HttpPost]
        public async Task<string> Export([FromBody]ActivityJoinSearchModel model)
        {
            model.PageIndex = 0;
            model.PageSize = int.MaxValue;
            var pageData = await this.List(model);
            if (pageData.Datas.Length > 0)
            {
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.AppendLine($"UID,姓名,性别,年龄,手机号");
                foreach (ActivityJoin item in pageData.Datas)
                {
                    stringBuilder.AppendLine($"{item.UserId},{item.Name},{(item.Sex == ActivityJoin_SexEnum.Man?"男":"女")},{item.Age},{item.Phone}");
                }
                return stringBuilder.ToString();
            }
            return "";
        }
    }

    public class ActivityJoinSearchModel : SearchRequestModel
    {

        public long? ActivityId { get; set; }
    }
}
